﻿using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.DependencyInjection;

namespace Xms.Abp.Core;

public class SequenceGenerator : ISequenceGenerator, ITransientDependency
{
    protected ISequenceProvider SequenceProvider { get; }
    public SequenceGenerator(
        IOptions<SequenceOptions> optionsAccessor,
        IEnumerable<ISequenceProvider> sequenceProviders)
    {
        SequenceProvider = sequenceProviders.FirstOrDefault(r => r.Name == (optionsAccessor.Value.ProviderName ?? "Snowflake"));
    }
    public long Create()
    {
        return SequenceProvider.Create();
    }

    public IEnumerable<long> Create(int quantity)
    {
        return SequenceProvider.Create(quantity);
    }
}
